<template>
  <div class="mod-goodsChoosePropertyValue">
  <el-dialog
    :title="'查看属性值'"
    :close-on-click-modal="false"
    :visible.sync="visible"
    width="70%">
    <el-form :model="dataForm" ref="dataForm" label-width="20px">
      <el-form-item>
        <el-breadcrumb separator="/">
          <el-breadcrumb-item>当前商品筛选属性</el-breadcrumb-item>
          <el-breadcrumb-item>{{this.dataForm.chooseTypeName}}</el-breadcrumb-item>
          <el-breadcrumb-item>{{this.dataForm.choosePropertyName}}</el-breadcrumb-item>
        </el-breadcrumb>
      </el-form-item>
      <el-form-item>
        <el-button v-if="isAuth('shopset:goodsChoosePropertyValue:list')" @click="loadChoosePropertyValueList()">刷新</el-button>
        <el-button v-if="isAuth('shopset:goodsChoosePropertyValue:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      style="width: 100%;">
      <el-table-column
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        prop="chooseTypeName"
        header-align="center"
        align="center"
        label="商品筛选类别">
      </el-table-column>
      <el-table-column
        prop="choosePropertyName"
        header-align="center"
        align="center"
        label="商品筛选属性">
      </el-table-column>
      <el-table-column
        prop="choosePropertyValueName"
        header-align="center"
        align="center"
        label="属性值">
      </el-table-column>
      <el-table-column
        prop="choosePropertyValueState"
        header-align="center"
        align="center"
        label="状态">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.choosePropertyValueState === 0" size="small" type="success"
          @click.native="updateChoosePropertyValueState(scope.row.choosePropertyValueId,1)" class="point1">启用</el-tag>
          <el-tag v-if="scope.row.choosePropertyValueState === 1" size="small" type="danger"
          @click.native="updateChoosePropertyValueState(scope.row.choosePropertyValueId,0)" class="point1">禁用</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button v-if="isAuth('shopset:goodsChoosePropertyValue:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.choosePropertyValueId)">修改</el-button>
          <el-button v-if="isAuth('shopset:goodsChoosePropertyValue:delete')" type="text" size="small" @click="deleteHandle(scope.row.choosePropertyValueId)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </el-dialog>
  <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="loadChoosePropertyValueList"></add-or-update>
  </div>
</template>

<script>
  import AddOrUpdate from './goodsChooseProperty-value-add-or-update'
  export default {
    data () {
      return {
        visible: false,
        addOrUpdateVisible: false,
        dataListLoading: false,
        dataList: [],
        dataForm: {
          choosePropertyId: '',
          choosePropertyName: '',
          chooseTypeName: ''
        }
      }
    },
    components: {
      AddOrUpdate
    },
    methods: {
      init (id) {
        this.visible = true
        this.dataListLoading = true
        this.dataForm.choosePropertyId = id
        // console.log(id)
        this.loadChooseProperty()
        this.loadChoosePropertyValueList()
      },
      loadChooseProperty () {
        this.$http({
          url: this.$http.adornUrl('/pig-center-biz/shopset/goodsChooseProperty/info'),
          method: 'post',
          params: this.$http.adornParams({
            'choosePropertyId': this.dataForm.choosePropertyId
          })
        }).then(({data}) => {
          // console.log(data)
          this.dataForm.choosePropertyName = data.goodsChooseProperty.choosePropertyName
          this.dataForm.chooseTypeName = data.goodsChooseProperty.chooseTypeName
        })
      },
      loadChoosePropertyValueList () {
        this.$http({
          url: this.$http.adornUrl('/pig-center-biz/shopset/goodsChoosePropertyValue/list'),
          method: 'get',
          params: this.$http.adornParams({
            'choosePropertyId': this.dataForm.choosePropertyId
          })
        }).then(({data}) => {
          this.dataList = data.list
          this.dataListLoading = false
        })
      },
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(this.dataForm.choosePropertyId, id)
        })
      },
      updateChoosePropertyValueState (id, state) {
        this.$http({
          url: this.$http.adornUrl('/pig-center-biz/shopset/goodsChoosePropertyValue/setState'),
          method: 'post',
          params: this.$http.adornParams({
            'choosePropertyValueId': id,
            'choosePropertyValueState': state
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500
            })
            this.dataListLoading = true
            this.loadChoosePropertyValueList()
          } else {
            this.$message.error(data.msg)
          }
        })
      },
      deleteHandle (id) {
        this.$confirm(`确定对[id=${id}]进行删除']操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/pig-center-biz/shopset/goodsChoosePropertyValue/delete'),
            method: 'post',
            params: this.$http.adornParams({
              'choosePropertyValueId': id
            })
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500
              })
              this.dataListLoading = true
              this.loadChoosePropertyValueList()
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      }
    }
  }
</script>

<style>
</style>
